<?php
namespace app\appclass\model;
use app\BaseModel;
use think\facade\Db;



class ClassLable extends BaseModel
{
    //定义表名
    protected $name = 'longbing_card_appclass_class_lable';


    /**
     * @author chenniang
     * @DataTime: 2021-05-11 16:00
     * @功能说明:添加
     */
    public function dataAdd($data){

        $res = $this->insert($data);

        return $res;

    }


    /**
     * @author chenniang
     * @DataTime: 2021-05-11 16:03
     * @功能说明:编辑
     */
    public function dataUpdate($dis,$data){

        $res = $this->where($dis)->where('status','>',-1)->update($data);

        return $res;

    }


    /**
     * @author chenniang
     * @DataTime: 2021-05-11 16:04
     * @功能说明:详情
     */
    public function dataInfo($dis){

        $data = $this->where($dis)->find();

        return !empty($data)?$data->toArray():[];

    }




    /**
     * @author chenniang
     * @DataTime: 2021-05-12 10:08
     * @功能说明:添加
     */
    public function adminDataAdd($data,$class_id){

        $dis = [

            'class_id' => $class_id,
        ];

        $this->where($dis)->delete();

        if(!empty($data['lable'])){

            foreach ($data['lable'] as $k=> $v){

                $data['lable'][$k]['class_id'] = $class_id;

                $data['lable'][$k]['uniacid']  = $data['uniacid'];

            }
            $this->saveAll($data['lable']);

        }

        return true;
    }


    /**
     * @author chenniang
     * @DataTime: 2021-05-14 14:41
     * @功能说明:
     */
    public function classLable($class_id){

        $dis = [

            'a.class_id' => $class_id,

            'b.status'   => 1

        ];

        $data = $this->alias('a')
                ->join('longbing_card_appclass_lable b','a.lable_id = b.id')
                ->where($dis)
                ->group('b.id')
                ->column('b.title');

        return !empty($data)?array_values($data):[];

    }


    /**
     * @author chenniang
     * @DataTime: 2021-05-14 14:41
     * @功能说明:
     */
    public function classLableList($class_id){


        $dis = [

            'a.class_id' => $class_id,

            'b.status'   => 1

        ];

        $data = $this->alias('a')
            ->join('longbing_card_appclass_lable b','a.lable_id = b.id')
            ->where($dis)
            ->field('a.*,b.title')
            ->group('b.id')
            ->select()
            ->toArray();

        return $data;

    }




}